package com.example.myapplication2

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import org.greenrobot.eventbus.EventBus

class aActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        checkAndRequestNotificationPermission()


        val fileName = getExternalFilesDir(null)!!.absoluteFile
        Log.e("tag-->", "data---$fileName")
        var aa = LogWriter(fileName)

        val app = application as App
        app.mShareModule.addData()
        app.mShareModule.mShareData.observe(this) {
            println("shareviewmodule data-->${it}")
        }

    }


    fun bt1(v: View) {
        val test = singleClass
        println("weither only--->$test")
        startActivity(Intent(this, bActivity::class.java))

    }

    fun bt2(v: View) {
        EventBus.getDefault().post(ReashEvent())
    }


    fun bt3(v: View) {

    }


    fun bt4(v: View) {

    }


    private fun checkAndRequestNotificationPermission() {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
            != PackageManager.PERMISSION_GRANTED
        ) {
            requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
        }
    }

    private val requestPermissionLauncher = registerForActivityResult(
        ActivityResultContracts.RequestPermission()
    ) { isGranted: Boolean ->
        if (isGranted) {
            Log.e("PermissionCheck", "通知权限已授予")
        } else {
            Log.e("PermissionCheck", "通知权限未授予")
        }
    }


}